#!/bin/bash

set -e

if [ "${MESON_SOURCE_ROOT}" ]
then
	PACKAGE=${1}
	VERSION=${2}
	top_builddir=${MESON_BUILD_ROOT}
	top_srcdir=${MESON_SOURCE_ROOT}
	subdir="."
else
	subdir="testsuite/basic"
fi

test -d ${top_builddir}/${subdir}/bootstrap || mkdir -p ${top_builddir}/${subdir}/bootstrap
cd ${top_builddir}/${subdir}/bootstrap

rm -f ${PACKAGE}-${VERSION}-1-src.tar.xz ${PACKAGE}-${VERSION}-1.tar.xz

if [ -d ${top_srcdir}/.git ]
then
	pushd ${top_srcdir}
	git archive-all --prefix=${PACKAGE}-${VERSION}/ ${PACKAGE}-${VERSION}.tar.gz
	popd
	cp -f ${top_srcdir}/${PACKAGE}-${VERSION}.tar.gz .
else
	exit 77
fi

cp -f ${top_srcdir}/data/sample.cygport ${PACKAGE}.cygport

${top_builddir}/bin/cygport-inplace ${PACKAGE}.cygport clean all
